{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e80154c2",
   "metadata": {},
   "source": [
    "-------------------\n",
    "* 本周主要内容：图像识别（人脸识别）\n",
    "* 记录人：洪梦瑶\n",
    "* 日期：2023年3月13日 周一\n",
    "-------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b3255730",
   "metadata": {},
   "source": [
    "## 上周内容\n",
    ">1. API文档阅读(考试) \n",
    ">2. requests模块(考试)\n",
    ">3. 百度通用图像识别"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5445ed3c",
   "metadata": {},
   "source": [
    "# 本周内容：Face++实践"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8a1eaf9f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1678679755,fb3d8b28-102e-47ea-832c-1ba6c07359d0', 'time_used': 162, 'faces': [{'face_token': '93cd351f32f4b7cb6799151495eb7857', 'face_rectangle': {'top': 361, 'left': 257, 'width': 260, 'height': 260}, 'attributes': {'gender': {'value': 'Male'}, 'age': {'value': 21}, 'smile': {'value': 14.377, 'threshold': 50.0}, 'headpose': {'pitch_angle': 5.8632784, 'roll_angle': -4.172601, 'yaw_angle': -15.150776}, 'blur': {'blurness': {'value': 0.147, 'threshold': 50.0}, 'motionblur': {'value': 0.147, 'threshold': 50.0}, 'gaussianblur': {'value': 0.147, 'threshold': 50.0}}, 'eyestatus': {'left_eye_status': {'no_glass_eye_open': 99.999, 'no_glass_eye_close': 0.0, 'normal_glass_eye_open': 0.001, 'normal_glass_eye_close': 0.0, 'dark_glasses': 0.0, 'occlusion': 0.0}, 'right_eye_status': {'no_glass_eye_open': 100.0, 'no_glass_eye_close': 0.0, 'normal_glass_eye_open': 0.0, 'normal_glass_eye_close': 0.0, 'dark_glasses': 0.0, 'occlusion': 0.0}}, 'emotion': {'anger': 7.907, 'disgust': 6.328, 'fear': 0.167, 'happiness': 80.119, 'neutral': 5.144, 'sadness': 0.167, 'surprise': 0.167}, 'facequality': {'value': 53.133, 'threshold': 70.1}, 'mouthstatus': {'surgical_mask_or_respirator': 0.0, 'other_occlusion': 0.0, 'close': 100.0, 'open': 0.0}, 'eyegaze': {'left_eye_gaze': {'position_x_coordinate': 0.53, 'position_y_coordinate': 0.443, 'vector_x_component': 0.177, 'vector_y_component': 0.157, 'vector_z_component': 0.971}, 'right_eye_gaze': {'position_x_coordinate': 0.533, 'position_y_coordinate': 0.431, 'vector_x_component': 0.071, 'vector_y_component': 0.242, 'vector_z_component': 0.968}}, 'skinstatus': {'health': 79.697, 'stain': 1.507, 'dark_circle': 6.603, 'acne': 5.27}, 'glass': {'value': 'None'}}}], 'image_id': '3ULE2iZe+geUjdpZdIb+Zw==', 'face_num': 1}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++ 人脸检测\n",
    "'''\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1.图片文件准备\n",
    "f = open('E:\\网络与新媒体\\software\\lyx.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "# 2.酬载准备\n",
    "payload = {\n",
    "    'api_key':'KKyDfiBX4scl6OfuCr3gnxuMchPKZM0O',\n",
    "    'api_secret':'UG_2MkCVGI8FiSqXQkDExKXrFztdWgbt',\n",
    "    'image_base64':img,\n",
    "    'return_attributes':'gender,age,smiling,headpose,facequality,blur,eyestatus,emotion,mouthstatus,eyegaze,skinstatus'}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "else:\n",
    "    print(response.status_code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dac8953c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
